<?php
use_stylesheet('list.css');
$kpidaysRaw=$sf_data->getRaw("kpidays");
?>

<div id="loader">
    <img  src="/images/loader.gif"/>
    <br>Updating...
</div>

<table id="lista">
<thead>
    <tr>
      <th>Plant</th>
      <th>Lastupdate</th>
      <th>Pr<br>[%]</th>
      <th>Rad<br>[kWh/mq]</th>
      <th>Expen<br>[kWh]</th>
      <th>Heq<br>[h]</th>
      <th>Tmod<br>[°C]</th>
      <th>Tenv<br>[°C]</th>
    </tr>
  <tr>
      <th class="order" colspan="8"><?php 
      if ($start != $end)
        echo $start->format("Y-m-d")." - ".$end->format("Y-m-d");
      else
        echo $start->format("Y-m-d")?>
      
      </th>
  </tr>
  </thead>
  <tbody>
    
    <?php
        $odd="even";
        $key=-1;
        foreach ($kpidaysRaw as $plantId=>$plantKpidays){
            $plant=Doctrine_Core::getTable("plant")->find($plantId);
            if (isset($plantKpidays)){
                
                foreach ($plantKpidays as $kpiday){
                    if (isset($kpiday["subplant"])) continue;
                    $key++;
                    $odd = fmod($key, 2) ? 'odd' : 'even';

                    ?>
                        <tr class="<?php echo $odd ?>">
                            <th class="highVis"><a href="<?php echo url_for('kpiday_show_plant',$plant) ?>"><?php echo $plant->getName() ?></a></th>
                            <td class="highVis"><?php echo $kpiday["lastupdate"] ?></td>
                            <td class="highVis">
          <?php                 if (($kpiday["pr"]>=0 && $kpiday["pr"]<1.3)) { ?>                     
                                <div class="donutHolder">
                                    <div class="donut"></div>
                                    <span class="donutData"><?php echo ($kpiday["pr"]*100)."%"  ?></span>   
                                </div>
          <?php                 }else{ 
                                    echo "NA";
                                }?>

                            </td>
                            <td class="highVis"><?php echo $kpiday["rad"] ?></td>
                            <td class="highVis"><?php echo $kpiday["expen"] ?></td>
                            <td class="highVis"><?php echo $kpiday["heq"] ?></td>
                            <td class="highVis"><?php echo $kpiday["tmod"] ?></td>
                            <td class="highVis"><?php echo $kpiday["tenv"] ?></td>
                        </tr> 
           <?php    
                 }
               }else{ 
                   $key++;
                   $odd = fmod($key, 2) ? 'odd' : 'even';
                        ?>
                        <tr class="<?php echo $odd ?>">
                            <th class="highVis"><a href="<?php echo url_for('kpiday_show_plant',$plant) ?>"><?php echo $plant->getName() ?></a></th>
                            <td class="redlight" colspan="7"> NA </td>
                        </tr>
    <?php           } 
        }?>
                    
               
        
  </tbody>
</table>